/**
 * 查询全部（通过游标方式）
 * @param {*} db 
 * @param {*} storeName 
 * @returns 
 */
export function getDataAllCursor(db, storeName) {
  return new Promise((resolve, reject) => {
    const request = db
      .transaction([storeName])
      .objectStore(storeName)
      .openCursor();
    const rows = [];
    request.onsuccess = function (event) {
      const cursor = event.atrget.result;
      if (cursor) {
        rows.push(cursor.value);
        cursor.continue();
      } else {
        resolve(rows);
      }
    };

    request.onerror = function (event) {
      reject(new Error(event.TABLE_HANDLE_ERROR));
    };
  });
}

/**
 * 查询全部(getAll)
 * @param {*} db 
 * @param {*} storeName 
 */
export function getDataAll(db, storeName) {
    return new Promise((resolve, reject) => {
        const request = db.transaction([storeName]).objectStore(storeName).getAll();

        request.onsuccess = function (event) {
            const result = event.target.result;
            resolve(result);
        
        }
        

        request.onerror = function (event) {
            reject(event);
        }
    })
}